<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组扩展求最大值和求和方法</title>
</head>

<body>
  <script>
    // ============================== 数组扩展求最大值和求和方法 ==============================
    // 1. 数组扩展求最大值/最小值
    // 2. 数组扩展求和方法

    const arr1 = [1, 2, 3, 234234234234324]
    const arr2 = [10, 20, 30, -2342]
    const arr3 = [66, 28, 36, 48, 9999999]

    // 数组扩展求最大值
    Array.prototype.max = function () {
      return Math.max(...this)
    }
    // 数组扩展求最小值
    Array.prototype.min = function () {
      return Math.min(...this)
    }
    // 数组扩展求求和
    Array.prototype.sum = function () {
      return this.reduce((prev, item) => prev + item, 0)
    }

    // 从而可以让数组调用 max min sum方法
    console.log(arr1.max())
    console.log(arr2.min())
    console.log(arr3.sum())


  </script>
</body>

</html>